package rpcclient

import (
	"net/rpc"

	"smartconn.cc/tosone/logstash"
)

// Client define
var Client *rpc.Client

// StartConn define
func StartConn() bool {
	logstash.Info("Init rpc client for app-end ...")
	var err error
	for {
		Client, err = rpc.DialHTTP("unix", "/tmp/nbc_service.rpc")
		if err != nil {
			logstash.Error(err.Error())
		} else {
			logstash.Info("Init rpc client for app-end successfully ...")
			break
		}
	}
	return true
}

// StopConn define
func StopConn() bool {
	logstash.Info("Stop rpc client for app-end ...")
	err := Client.Close()
	if err != nil {
		logstash.Error(err.Error())
		return false
	}
	return true
}
